package com.etc.myblog.biz;

import java.util.ArrayList;
import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.etc.myblog.entity.Reply;
import com.etc.myblog.dao.ReplyDao;
import com.etc.myblog.util.SessionFactoryUtil;

public class ReplyBiz {
	
	public List<Reply> findRepByCommId(int commentId) {
		List<Reply> list = new ArrayList<Reply>();
		SqlSession session = SessionFactoryUtil.getSession();
		try {
			ReplyDao dao = session.getMapper(ReplyDao.class);
			list = dao.findRepByCommId(commentId);
		} catch (Exception e) {
			System.out.println(e.getMessage());
		} finally {
			session.close();
		}
		return list;
	}
	
	public void addReply(Reply reply) {
		SqlSession session = SessionFactoryUtil.getSession();
		try {
			ReplyDao dao = session.getMapper(ReplyDao.class);
			dao.addReply(reply);
			session.commit();
		} catch (Exception e) {
			System.out.println(e.getMessage());
			session.rollback();
		} finally {
			session.close();
		}
	}
}
